/*
 * @Author: Marte
 * @Date:   2016-11-08 15:35:16
 * @Last Modified by:   Marte
 * @Last Modified time: 2016-11-09 14:13:50
 */

'use strict';

function getParamByName(name) {
    var url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}

//全局参数
var globalParam = {
    uid: getParamByName('uid'),
    RED: getParamByName('RED'),
    CRT: getParamByName('CRT'),
    DEL: getParamByName('DEL'),
    UPD: getParamByName('UPD'),
    EXP: getParamByName('EXP'),
    canRED: function() {
        return (this.RED === 'Y');
    },
    canCRT: function() {
        return (this.CRT === 'Y');
    },
    canDEL: function() {
        return (this.DEL === 'Y');
    },
    canUPD: function() {
        return (this.UPD === 'Y');
    },
    canEXP: function() {
        return (this.EXP === 'Y');
    },
    paramString: function() {
        return 'uid=' + this.uid + '&RED=' + this.RED + '&CRT=' + this.CRT + '&DEL=' + this.DEL + "&UPD=" + this.UPD + "&EXP=" + this.EXP;
    }
}

if (!globalParam.uid) {
    globalParam.uid = 'HWJAUU2-SDI1229';
    globalParam.RED = 'Y';
    globalParam.CRT = 'Y';
    globalParam.DEL = 'Y';
    globalParam.UPD = 'Y';
    globalParam.EXP = 'Y';
}
